import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:im_module/map/BDMapPage.dart';
import 'package:tencent_im_sdk_plugin/models/v2_tim_message.dart';

class LocationMessageWidget extends StatelessWidget {
  final V2TimMessage message;

  LocationMessageWidget(this.message);

  @override
  Widget build(BuildContext context) {
    String url =
        "http://api.map.baidu.com/staticimage?width=300&height=180&center=${message.locationElem?.longitude},${message.locationElem?.latitude}&markers=${message.locationElem?.longitude},${message.locationElem?.latitude}&zoom=18";

    return GestureDetector(
      onTap: () {
        Navigator.push(context, new MaterialPageRoute(builder: (ctx) {
          return BDMapPage(
              message.locationElem?.latitude, message.locationElem?.longitude);
        }));
      },
      child: Container(
        color: Colors.white,
        constraints: BoxConstraints(maxWidth: 210),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text("${message.locationElem?.desc}",
                  maxLines: 2, overflow: TextOverflow.ellipsis,style: TextStyle(fontSize: 14,color: Color(0xff666666)),),
            ),
            CachedNetworkImage(
              imageUrl: url,
              width: 210,
              height: 100,
              fit: BoxFit.fill,
              placeholder: (context, url) => Container(
                constraints: BoxConstraints(maxWidth: 25, maxHeight: 25),
                child: CupertinoActivityIndicator(radius: 15),
              ),
              errorWidget: (context, url, error) => Icon(Icons.error),
            )
          ],
        ),
      ),
    );
  }
}
